﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SystemTrayCountdownTimerEntities;
using SystemTrayCountdownTimerRepository;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Logging;


namespace SystemTrayCountdownTimerDA
{
    public class Control : IControlEntity
    {
        private Database cT;
        private String sql;

        public Control()
        {
            this.cT = DatabaseFactory.CreateDatabase("CT");
        }

        //public IEnumerable<Control> GetControl(Int16 idx)
        //{
        //    

        //    return null;
        //}

        //IEnumerable<SystemTrayCountdownTimerEntities.Control> IControl.GetControl(short idx)
        //{
        //    throw new NotImplementedException();
        //}

        public IEnumerable<ControlEntity> GetControl(short idx)
        {
            sql = @"select * from Control where Idx=1";

            DataAccessor<ControlEntity> ca = this.cT.CreateSqlStringAccessor(  //this.cT.CreateSqlStringAccessor(
              sql,
              MapBuilder<ControlEntity>
              .MapNoProperties()
             .Map(x => x.Idx).ToColumn("Idx")
             .Map(x => x.IsEnabled).ToColumn("IsEnabled")
             .Map(x => x.EndDateTime).ToColumn("EndDateTime")
             .Map(X => X.ShowDays).ToColumn("ShowDays")
             .Map(X => X.ShowHours).ToColumn("ShowHours")
             .Map(X => X.ShowMinutes).ToColumn("ShowMinutes")
             .Map(X => X.ShowSeconds).ToColumn("ShowSeconds")
              .Build());

            return ca.Execute().ToList();
        }
    }
}
